package com.ymatou.iapi.godfreightmgr.testcase;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import com.ymatou.iapi.godfreightmgr.parameter.CreateFreightDetailDto;
import com.ymatou.iapi.godfreightmgr.parameter.CreateFreightDto;
import com.ymatou.iapi.godfreightmgr.parameter.CreateFreightTemplateBean;
import com.ymatou.iapi.godfreightmgr.parameter.FreightInfoVo;
import com.ymatou.iapi.godfreightmgr.service.CreateFreightTemplateCall;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AssertService;
import com.ymttest.business.service.GodfreightmgrService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.freight_template;
import com.ymttest.database.model.freight_template_detail;
import com.ymttest.database.sqlwapper.godfreight.freight_templateWapper;
import com.ymttest.database.sqlwapper.godfreight.freight_template_detailWapper;
import com.ymttest.utils.AgentUsers;
import com.ymttest.utils.MapUtil;

/**
*创建运费模板PID
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_CreateFreightTemplate{
	private static CreateFreightTemplateBean createfreighttemplateBean;
	private static CreateFreightTemplateCall createfreighttemplateCall;
	private static freight_templateWapper templateWapper = new freight_templateWapper();
	private static freight_template_detailWapper detailWapper = new freight_template_detailWapper();
	//渠道商
	private static int sellerId = AgentUsers.rootUserId;
	private static String sellerName = "NickautoTest";
	//代理商1
	private static int agentUserId1 = AgentUsers.agentUserId1;
	private static String agentUserName1 = "NickautoTest";
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("创建运费模板PID");
	}

	@Before
	public void caseUp() {
		createfreighttemplateBean=new CreateFreightTemplateBean();
		createfreighttemplateCall=new CreateFreightTemplateCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(createfreighttemplateCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	public CreateFreightDetailDto setCreateFreightDetailDto(int calcModel){
		CreateFreightDetailDto createFreightDetail = new CreateFreightDetailDto();
		createFreightDetail.setDefaultTemplate(false);//是否默认运费模板
		List<String> deliveryRegion = new ArrayList<>();
		deliveryRegion.add("啊啊啊");
		createFreightDetail.setDeliveryRegion(deliveryRegion);

		if (calcModel == 1){
			createFreightDetail.setFirstNum(1);//首件重量
			createFreightDetail.setAddNum(2);//续件重量
			createFreightDetail.setFirstFee(new BigDecimal(10));//首件/首重运费
			createFreightDetail.setAddFee(new BigDecimal(5));//续件 / 续重 运费
		}else if (calcModel == 2){
			createFreightDetail.setFirstWeight(new BigDecimal(1));//首件重量
			createFreightDetail.setAddWeight(new BigDecimal(2));//续件重量
			createFreightDetail.setFirstFee(new BigDecimal(15));//首件/首重运费
			createFreightDetail.setAddFee(new BigDecimal(10));//续件 / 续重 运费
		}
		return createFreightDetail;
	}


	public FreightInfoVo getTgtFreightInfoVo(CreateFreightTemplateBean templateBean){
        FreightInfoVo freightInfoVo = new FreightInfoVo();
        freightInfoVo.setAgentFreight(templateBean.getAgentFreight());
        freightInfoVo.setMainFreight(templateBean.getMainFreight());
        freightInfoVo.setTemplateName(templateBean.getTemplateName());
        freightInfoVo.setShareTemplate(templateBean.getShareTemplate());
        freightInfoVo.setSellerId(templateBean.getSellerId());
        return freightInfoVo;
    }

    public void verifyDB(CreateFreightTemplateBean templateBean,int templateId){
        FreightInfoVo tgtFreightInfoVo = getTgtFreightInfoVo(templateBean);
        tgtFreightInfoVo.setTemplateId(templateId);
        freight_template template = templateWapper.selectByPrimaryKey(templateId);
        List<freight_template_detail> templateDetails = detailWapper.selectByTemplateId(templateId);
        //追加Currency验证
        Logger.verifyEquals(templateBean.getCurrency(), template.getCurrency(), "验证Currency");
        
        FreightInfoVo actFreightInfoVo = new FreightInfoVo();
        actFreightInfoVo.setSellerId(template.getSellerId());
        actFreightInfoVo.setShareTemplate(template.getIsShareTemplate());
        actFreightInfoVo.setTemplateId(templateId);
        actFreightInfoVo.setTemplateName(template.getTemplateName());

        List<freight_template_detail> mainFreightDetail = templateDetails.stream().filter(x -> x.getSaleMode() == 1 || x.getSaleMode() == 3).collect(Collectors.toList());
        List<freight_template_detail> agentFreightDetail = templateDetails.stream().filter(x -> x.getSaleMode() == 2).collect(Collectors.toList());

        CreateFreightDto mainFreight = new CreateFreightDto();
        mainFreight.setCalcModel(template.getDirectSaleCalcFeeMode());
        List<CreateFreightDetailDto> createFreightDetailDtos = mainFreightDetail.stream().map(x -> mapCreateFreightDetailDto(x)).collect(Collectors.toList());
        mainFreight.setTemplateItems(createFreightDetailDtos);
        if (!CollectionUtils.isEmpty(agentFreightDetail)){
            CreateFreightDto agentFreight = new CreateFreightDto();
            agentFreight.setCalcModel(template.getAgentSaleCalcFeeMode());
            List<CreateFreightDetailDto> createFreightDetailDtos1 = agentFreightDetail.stream().map(x -> mapCreateFreightDetailDto(x)).collect(Collectors.toList());
            agentFreight.setTemplateItems(createFreightDetailDtos1);
            actFreightInfoVo.setAgentFreight(agentFreight);
        }
        actFreightInfoVo.setMainFreight(mainFreight);

        Logger.debug("actFreightInfoVo:"+actFreightInfoVo);

        Map<String, Object> tgtMap = MapUtil.pojoToMap(tgtFreightInfoVo);
        tgtMap.remove("mainFreight");
        tgtMap.remove("agentFreight");
        Map<String, Object> actMap = MapUtil.pojoToMap(actFreightInfoVo);
        actMap.remove("mainFreight");
        actMap.remove("agentFreight");
        AssertService.assertResultEqual(tgtMap, actMap);

        CreateFreightDto tgtmainFreight = tgtFreightInfoVo.getMainFreight();
        CreateFreightDto actmainFreight = actFreightInfoVo.getMainFreight();
        Map<String, Object> tgtmainFreightMap = MapUtil.pojoToMap(tgtmainFreight);
        tgtmainFreightMap.remove("templateItems");
        Map<String, Object> actmainFreightMap = MapUtil.pojoToMap(actmainFreight);
        actmainFreightMap.remove("templateItems");
        AssertService.assertResultEqual(tgtmainFreightMap, actmainFreightMap);

        List<CreateFreightDetailDto> tgttemplateItems = tgtmainFreight.getTemplateItems();
        List<CreateFreightDetailDto> acttemplateItems = actmainFreight.getTemplateItems();
        tgttemplateItems.forEach(p->{
            CreateFreightDetailDto createFreightDetailDto = acttemplateItems.stream().filter(x -> x.getFirstFee().equals(p.getFirstFee())).findFirst().orElse(null);
            if (createFreightDetailDto!=null){
                Map<String, Object> map = MapUtil.pojoToMap(p);
                Map<String, Object> map1 = MapUtil.pojoToMap(createFreightDetailDto);
                AssertService.assertResultEqual(map, map1);
            }
        });

        if (tgtFreightInfoVo.getAgentFreight()!=null){
            CreateFreightDto tgtmainFreight1 = tgtFreightInfoVo.getAgentFreight();
            CreateFreightDto actmainFreight1 = actFreightInfoVo.getAgentFreight();
            Map<String, Object> tgtmainFreightMap1 = MapUtil.pojoToMap(tgtmainFreight1);
            tgtmainFreightMap1.remove("templateItems");
            Map<String, Object> actmainFreightMap1 = MapUtil.pojoToMap(actmainFreight1);
            actmainFreightMap.remove("templateItems");
            AssertService.assertResultEqual(tgtmainFreightMap1, actmainFreightMap1);

            List<CreateFreightDetailDto> tgttemplateItems1 = tgtmainFreight1.getTemplateItems();
            List<CreateFreightDetailDto> acttemplateItems1 = actmainFreight1.getTemplateItems();
            tgttemplateItems1.forEach(p->{
                CreateFreightDetailDto createFreightDetailDto = acttemplateItems1.stream().filter(x -> x.getFirstFee().equals(p.getFirstFee())).findFirst().orElse(null);
                if (createFreightDetailDto!=null){
                    Map<String, Object> map = MapUtil.pojoToMap(p);
                    Map<String, Object> map1 = MapUtil.pojoToMap(createFreightDetailDto);
                    AssertService.assertResultEqual(map, map1);
                }
            });
        }

    }

    public CreateFreightDetailDto mapCreateFreightDetailDto(freight_template_detail templateDetail){
        CreateFreightDetailDto createFreightDetailDto = new CreateFreightDetailDto();
        createFreightDetailDto.setDefaultTemplate(templateDetail.getIsDefault());
        createFreightDetailDto.setDeliveryRegion(StringUtils.isEmpty(templateDetail) ? Arrays.asList() : Arrays.asList(templateDetail.getDeliveryCity().split(",")));
        createFreightDetailDto.setFirstFee(templateDetail.getFirstFee());
        createFreightDetailDto.setAddFee(templateDetail.getAddFee());
        if (templateDetail.getCalcFeeMode()==1){
            createFreightDetailDto.setFirstNum(templateDetail.getFirstNum().intValue());
            createFreightDetailDto.setAddNum(templateDetail.getAddNum().intValue());
        }else if (templateDetail.getCalcFeeMode()==2){
            createFreightDetailDto.setFirstWeight(templateDetail.getFirstNum());
            createFreightDetailDto.setAddWeight(templateDetail.getAddNum());
        }
        return createFreightDetailDto;
    }

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_01() {
		Logger.start(true,"渠道商创建主运费模板和代理运费模板，创建成功");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),1,1);
			createfreighttemplateBean.getMainFreight().getTemplateItems().get(0).setFirstFee(new BigDecimal(1.07));
			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();			
			Logger.verifyEquals("200",createfreighttemplateCall.getString("code"),"验证code");
			int templateId = createfreighttemplateCall.getJsonObject().get("data").getAsJsonObject().get("templateId").getAsInt();
			verifyDB(createfreighttemplateBean,templateId);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_02() {
		Logger.start(true,"渠道商创建共享运费模板，创建成功");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),1,2);
			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("200",createfreighttemplateCall.getString("code"),"验证code");
			int templateId = createfreighttemplateCall.getJsonObject().get("data").getAsJsonObject().get("templateId").getAsInt();
			verifyDB(createfreighttemplateBean,templateId);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_03() {
		Logger.start(true,"渠道商创建主运费模板（按重）和代理运费模板（按件），创建成功");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),1,1);
			createfreighttemplateBean.setMainFreight(null);
			CreateFreightDto createFreightDto = new CreateFreightDto();
			createFreightDto.setCalcModel(2);

			CreateFreightDetailDto createFreightDetail = new CreateFreightDetailDto();
			List<String> deliveryRegion = new ArrayList<>();
			createFreightDetail.setDefaultTemplate(true);//是否默认运费模板
			deliveryRegion.add("北京");
			createFreightDetail.setDeliveryRegion(deliveryRegion);//配送区域，非默认运费模板必填
			createFreightDetail.setFirstWeight(new BigDecimal(1));//首件重量
			createFreightDetail.setAddWeight(new BigDecimal(2));//续件重量
			createFreightDetail.setFirstFee(new BigDecimal(15));//首件/首重运费
			createFreightDetail.setAddFee(new BigDecimal(10));//续件 / 续重 运费

			List<CreateFreightDetailDto> templateItems = new ArrayList<>();
			templateItems.add(createFreightDetail);
			createFreightDto.setTemplateItems(templateItems);//运费明细内容

			createfreighttemplateBean.setMainFreight(createFreightDto);

			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("200",createfreighttemplateCall.getString("code"),"验证code");
			int templateId = createfreighttemplateCall.getJsonObject().get("data").getAsJsonObject().get("templateId").getAsInt();
			verifyDB(createfreighttemplateBean,templateId);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_CreateFreightTemplate_04() {
		Logger.start(true,"代理商创建运费模板，创建失败");
		try {
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(agentUserId1,1,1);
			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("201",createfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_CreateFreightTemplate_05() {
		Logger.start(true,"渠道商无代理创建代理运费模板，创建失败");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),1,1);
			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("201",createfreighttemplateCall.getString("code"),"验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_06() {
		Logger.start(true,"高级运营创建运费模板，创建成功");
		try {
			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_07() {
		Logger.start(true,"创建运费模板超过20个，创建失败");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			for (int i=0;i<21;i++){
				createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),1,1);
				createfreighttemplateBean.setPolicyModel(1);
				createfreighttemplateCall.setData(createfreighttemplateBean);
				createfreighttemplateCall.callService();
			}
			Logger.verifyEquals("400",createfreighttemplateCall.getString("code"),"验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_08() {
		Logger.start(true,"创建运费模板名称重复，创建失败");
		try {
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(sellerId,1,1);
			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			createfreighttemplateCall.callService();
			Logger.verifyEquals("400",createfreighttemplateCall.getString("code"),"验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_CreateFreightTemplate_09() {
		Logger.start(true,"创建运费模板首重/首件运费小于0，创建失败");
		try {
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(sellerId,1,2);
			createfreighttemplateBean.getMainFreight().getTemplateItems().get(0).setFirstFee(new BigDecimal(-1));
			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("400",createfreighttemplateCall.getString("code"),"验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_CreateFreightTemplate_10() {
		Logger.start(true,"创建运费模板续件/续重小于0，创建失败");
		try {
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(sellerId,1,2);
			createfreighttemplateBean.getMainFreight().getTemplateItems().get(0).setAddFee(new BigDecimal(-1));
			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("400",createfreighttemplateCall.getString("code"),"验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_11() {
		Logger.start(true,"创建共享运费模板，无默认运费模板，创建失败");
		try {
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(sellerId,1,2);
			createfreighttemplateBean.getMainFreight().getTemplateItems().get(0).setDefaultTemplate(false);
			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("400",createfreighttemplateCall.getString("code"),"验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_111() {
		Logger.start(true,"创建代理运费模板，无代理默认运费模板，创建失败");
		try {
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(sellerId,1,1);
			createfreighttemplateBean.getAgentFreight().getTemplateItems().get(0).setDefaultTemplate(false);
			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("400",createfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_12() {
		Logger.start(true,"创建非默认运费模板，区域未填，创建失败");
		try {
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(sellerId,1,2);

			CreateFreightDto createFreightDto = new CreateFreightDto();
			createFreightDto.setCalcModel(2);

			CreateFreightDetailDto createFreightDetail = new CreateFreightDetailDto();
			createFreightDetail.setDefaultTemplate(false);//是否默认运费模板
			createFreightDetail.setFirstWeight(new BigDecimal(1));//首件重量
			createFreightDetail.setAddWeight(new BigDecimal(2));//续件重量
			createFreightDetail.setFirstFee(new BigDecimal(15));//首件/首重运费
			createFreightDetail.setAddFee(new BigDecimal(10));//续件 / 续重 运费

			List<CreateFreightDetailDto> templateItems = new ArrayList<>();
			templateItems.add(createFreightDetail);
			templateItems.add(createfreighttemplateBean.getMainFreight().getTemplateItems().get(0));
			createFreightDto.setTemplateItems(templateItems);//运费明细内容

			createfreighttemplateBean.setMainFreight(createFreightDto);

			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("400",createfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_13() {
		Logger.start(true,"创建主运费模板，按件，首件小于0，创建失败");
		try {
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(sellerId,1,2);
			createfreighttemplateBean.getMainFreight().getTemplateItems().get(0).setFirstNum(-1);
			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("400",createfreighttemplateCall.getString("code"),"验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_14() {
		Logger.start(true,"创建主运费模板，按重，首重小于0，创建失败");
		try {
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(sellerId,2,2);
			createfreighttemplateBean.getMainFreight().getTemplateItems().get(0).setFirstWeight(new BigDecimal(-1));
			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("400",createfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_15() {
		Logger.start(true,"创建运费模板，模板信息为空，创建失败");
		try {
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(sellerId,1,2);
			createfreighttemplateBean.setMainFreight(null);
			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("400",createfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_16() {
		Logger.start(true,"创建运费模板，无默认运费，创建失败");
		try {
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(sellerId,1,2);
			createfreighttemplateBean.getMainFreight().getTemplateItems().get(0).setDefaultTemplate(false);
			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("400",createfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_17() {
		Logger.start(true,"创建运费模板，配送区域重复，创建失败");
		try {
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(sellerId,2,2);

			CreateFreightDto createFreightDto = new CreateFreightDto();
			createFreightDto.setCalcModel(2);

			CreateFreightDetailDto createFreightDetail = new CreateFreightDetailDto();
			createFreightDetail.setDefaultTemplate(false);//是否默认运费模板
			List<String> deliveryRegion = new ArrayList<>();
			deliveryRegion.add("北京");
			createFreightDetail.setDeliveryRegion(deliveryRegion);
			createFreightDetail.setFirstWeight(new BigDecimal(1));//首件重量
			createFreightDetail.setAddWeight(new BigDecimal(2));//续件重量
			createFreightDetail.setFirstFee(new BigDecimal(15));//首件/首重运费
			createFreightDetail.setAddFee(new BigDecimal(10));//续件 / 续重 运费

			CreateFreightDetailDto createFreightDetail1 = new CreateFreightDetailDto();
			createFreightDetail1.setDefaultTemplate(false);//是否默认运费模板
			createFreightDetail1.setDeliveryRegion(deliveryRegion);
			createFreightDetail1.setFirstWeight(new BigDecimal(1));//首件重量
			createFreightDetail1.setAddWeight(new BigDecimal(2));//续件重量
			createFreightDetail1.setFirstFee(new BigDecimal(15));//首件/首重运费
			createFreightDetail1.setAddFee(new BigDecimal(10));//续件 / 续重 运费

			List<CreateFreightDetailDto> templateItems = new ArrayList<>();
			templateItems.add(createFreightDetail);
			templateItems.add(createFreightDetail1);
			createfreighttemplateBean.getMainFreight().getTemplateItems().get(0).setDeliveryRegion(deliveryRegion);
			templateItems.add(createfreighttemplateBean.getMainFreight().getTemplateItems().get(0));
			createFreightDto.setTemplateItems(templateItems);//运费明细内容

			createfreighttemplateBean.setMainFreight(createFreightDto);

			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("400",createfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_18() {
		Logger.start(true,"创建运费模板，配送区域不存在，创建失败");
		try {
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(sellerId,1,2);

			CreateFreightDto createFreightDto = new CreateFreightDto();
			createFreightDto.setCalcModel(2);

			CreateFreightDetailDto createFreightDetail = new CreateFreightDetailDto();
			createFreightDetail.setDefaultTemplate(false);//是否默认运费模板
			List<String> deliveryRegion = new ArrayList<>();
			deliveryRegion.add("啊啊啊");
			createFreightDetail.setDeliveryRegion(deliveryRegion);
			createFreightDetail.setFirstWeight(new BigDecimal(1));//首件重量
			createFreightDetail.setAddWeight(new BigDecimal(2));//续件重量
			createFreightDetail.setFirstFee(new BigDecimal(15));//首件/首重运费
			createFreightDetail.setAddFee(new BigDecimal(10));//续件 / 续重 运费

			List<CreateFreightDetailDto> templateItems = new ArrayList<>();
			templateItems.add(createFreightDetail);
			templateItems.add(createfreighttemplateBean.getMainFreight().getTemplateItems().get(0));
			createFreightDto.setTemplateItems(templateItems);//运费明细内容

			createfreighttemplateBean.setMainFreight(createFreightDto);

			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("400",createfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_19() {
		Logger.start(true,"创建代理运费模板，代理运费模板为空，创建失败");
		try {
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(sellerId,1,1);
			createfreighttemplateBean.setAgentFreight(null);
			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("400",createfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_20() {
		Logger.start(true,"创建共享运费模板，江浙沪包邮，创建成功");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),1,2);

			CreateFreightDto createFreightDto = new CreateFreightDto();
			int calcModel = 1;
			createFreightDto.setCalcModel(calcModel);
			CreateFreightDetailDto createFreightDetailDto1 = setCreateFreightDetailDto(calcModel);
			createFreightDetailDto1.setDeliveryRegion(Arrays.asList("江苏省","浙江省","上海市"));
			createFreightDetailDto1.setFirstNum(1);
			createFreightDetailDto1.setFirstFee(new BigDecimal(0));
			createFreightDetailDto1.setAddFee(new BigDecimal(0));
			createFreightDetailDto1.setAddNum(5);
			List<CreateFreightDetailDto> templateItems = new ArrayList<>();
			templateItems.add(createFreightDetailDto1);
			templateItems.add(createfreighttemplateBean.getMainFreight().getTemplateItems().get(0));
			createfreighttemplateBean.getMainFreight().setCalcModel(1);
			createfreighttemplateBean.getMainFreight().setTemplateItems(templateItems);

			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("200",createfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_21() {
		Logger.start(true,"创建共享运费模板，创建两个默认模板，创建失败");
		try {
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(sellerId,1,2);

			CreateFreightDto createFreightDto = new CreateFreightDto();
			int calcModel = 1;
			createFreightDto.setCalcModel(calcModel);
			CreateFreightDetailDto createFreightDetailDto1 = setCreateFreightDetailDto(calcModel);
			createFreightDetailDto1.setDefaultTemplate(true);
			createFreightDetailDto1.setDeliveryRegion(Arrays.asList("江苏省","浙江省","上海市"));
			createFreightDetailDto1.setFirstNum(1);
			createFreightDetailDto1.setFirstFee(new BigDecimal(0));
			createFreightDetailDto1.setAddFee(new BigDecimal(0));
			createFreightDetailDto1.setAddNum(5);
			List<CreateFreightDetailDto> templateItems = new ArrayList<>();
			templateItems.add(createFreightDetailDto1);
			templateItems.add(createfreighttemplateBean.getMainFreight().getTemplateItems().get(0));
			createfreighttemplateBean.getMainFreight().setCalcModel(1);
			createfreighttemplateBean.getMainFreight().setTemplateItems(templateItems);

			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("400",createfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_22() {
		Logger.start(true,"创建运费模板，创建两个主运费默认模板，创建失败");
		try {
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(sellerId,1,1);

			CreateFreightDto createFreightDto = new CreateFreightDto();
			int calcModel = 1;
			createFreightDto.setCalcModel(calcModel);
			CreateFreightDetailDto createFreightDetailDto1 = setCreateFreightDetailDto(calcModel);
			createFreightDetailDto1.setDefaultTemplate(true);
			createFreightDetailDto1.setDeliveryRegion(Arrays.asList("江苏省","浙江省","上海市"));
			createFreightDetailDto1.setFirstNum(1);
			createFreightDetailDto1.setFirstFee(new BigDecimal(0));
			createFreightDetailDto1.setAddFee(new BigDecimal(0));
			createFreightDetailDto1.setAddNum(5);
			List<CreateFreightDetailDto> templateItems = new ArrayList<>();
			templateItems.add(createFreightDetailDto1);
			templateItems.add(createfreighttemplateBean.getMainFreight().getTemplateItems().get(0));
			createfreighttemplateBean.getMainFreight().setCalcModel(1);
			createfreighttemplateBean.getMainFreight().setTemplateItems(templateItems);

			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("400",createfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_23() {
		Logger.start(true,"创建运费模板，创建两个代理运费默认模板，创建失败");
		try {
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(sellerId,1,1);

			CreateFreightDto createFreightDto = new CreateFreightDto();
			int calcModel = 1;
			createFreightDto.setCalcModel(calcModel);
			CreateFreightDetailDto createFreightDetailDto1 = setCreateFreightDetailDto(calcModel);
			createFreightDetailDto1.setDefaultTemplate(true);
			createFreightDetailDto1.setDeliveryRegion(Arrays.asList("江苏省","浙江省","上海市"));
			createFreightDetailDto1.setFirstNum(1);
			createFreightDetailDto1.setFirstFee(new BigDecimal(0));
			createFreightDetailDto1.setAddFee(new BigDecimal(0));
			createFreightDetailDto1.setAddNum(5);
			List<CreateFreightDetailDto> templateItems = new ArrayList<>();
			templateItems.add(createFreightDetailDto1);
			templateItems.add(createfreighttemplateBean.getAgentFreight().getTemplateItems().get(0));
			createfreighttemplateBean.getAgentFreight().setCalcModel(1);
			createfreighttemplateBean.getAgentFreight().setTemplateItems(templateItems);
			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("400",createfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_CreateFreightTemplate_24() {
		Logger.start(true,"创建代理运费模板，isShareTemplate为true，创建失败");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),1,1);
			createfreighttemplateBean.setIsShareTemplate(true);
			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("400",createfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_25() {
		Logger.start(true,"第二次创建运费模板，设置组合策略，创建成功");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(), 1, 1);

			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("200",createfreighttemplateCall.getString("code"),"验证code");

			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(), 1, 1);
			createfreighttemplateBean.setPolicyModel(1);
			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("200",createfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	//TODO 待确认 目前看下来是可以创建的
	public void Tc_CreateFreightTemplate_26() {
		Logger.start(true,"第二次创建运费模板，没有设置组合策略，创建失败");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(), 1, 1);

			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("200",createfreighttemplateCall.getString("code"),"验证code");

			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(), 1, 1);
			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("400",createfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_27() {
		Logger.start(true,"创建运费模板，没有设置币种，创建失败");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(), 1, 1);
			createfreighttemplateBean.setCurrency(null);

			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("400",createfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_28() {
		Logger.start(true,"第二次创建运费模板，客服不存在，创建失败");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(001, 1, 1);

			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("400",createfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_029() {
		Logger.start(true,"渠道商创建主运费模板和代理运费模板，创建成功-外汇标价CNY");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),1,1);
			createfreighttemplateBean.setCurrency("CNY");
			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();			
			Logger.verifyEquals("200",createfreighttemplateCall.getString("code"),"验证code");
			int templateId = createfreighttemplateCall.getJsonObject().get("data").getAsJsonObject().get("templateId").getAsInt();
			verifyDB(createfreighttemplateBean,templateId);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_29() {
		Logger.start(true,"创建运费模板，币种和商户结算币种不一致，创建失败");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(), 1, 1);
			createfreighttemplateBean.setCurrency("AUD");
			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			//返回报文{"code":400,"message":"运费模板币种与商户结算币种不一致","data":null}
			//20200428 现在不切币种了
			Logger.verifyEquals("200",createfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_30() {
		Logger.start(true,"创建运费模板，首重运费小数点后面有数字，创建失败");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			createmchBean.setCountry("JPN");
			GodmchManageCallService.createmchCallForChannel(createmchBean);

			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(), 1, 1);
			createfreighttemplateBean.setCurrency("JPY");
			createfreighttemplateBean.getMainFreight().getTemplateItems().get(0).setFirstFee(new BigDecimal(1.06));
			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("400",createfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_31() {
		Logger.start(true,"创建运费模板，续重运费小数点后面有数字，创建失败");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			createmchBean.setCountry("JPN");
			GodmchManageCallService.createmchCallForChannel(createmchBean);

			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(), 1, 1);
			createfreighttemplateBean.setCurrency("JPY");
			createfreighttemplateBean.getMainFreight().getTemplateItems().get(0).setAddFee(new BigDecimal(1.06));
			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("400",createfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_CreateFreightTemplate_32() {
		Logger.start(true,"创建运费模板，续重运费小数点后面有数字，创建失败");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(), 1, 1);
			createfreighttemplateBean.getMainFreight().getTemplateItems().get(0).setFirstFee(new BigDecimal(1.04));
			createfreighttemplateBean.getMainFreight().getTemplateItems().get(0).setAddFee(new BigDecimal(1.03));
			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("400",createfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_CreateFreightTemplate_33() {
		Logger.start(true,"创建运费模板，续重运费小数点后面有数字，创建失败");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(), 1, 1);
			createfreighttemplateBean.getMainFreight().getTemplateItems().get(0).setFirstFee(new BigDecimal(1.07));
			createfreighttemplateBean.getMainFreight().getTemplateItems().get(0).setAddFee(new BigDecimal(1.00));
			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("400",createfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_34() {
		Logger.start(true,"创建运费模板，续重运费小数点后面有数字，创建失败");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(), 1, 1);
			createfreighttemplateBean.getMainFreight().getTemplateItems().get(0).setFirstFee(new BigDecimal(0));
			createfreighttemplateBean.getMainFreight().getTemplateItems().get(0).setAddFee(new BigDecimal(0));
			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("200",createfreighttemplateCall.getString("code"),"验证code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_35() {
		Logger.start(true,"渠道商创建主运费模板和代理运费模板，渠道支持海外地址,地区都是海外地址创建成功");
		try {
			Integer mchId=500802465;
			GodfreightmgrService.deleteBySellerId(500802465);
			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(mchId,1,2);

			CreateFreightDto createFreightDto = new CreateFreightDto();
			int calcModel = 1;
			createFreightDto.setCalcModel(calcModel);
			CreateFreightDetailDto createFreightDetailDto1 = setCreateFreightDetailDto(calcModel);
//			List<String> deliveryRegion=new ArrayList<>();
//			deliveryRegion.add("湖北省");
//			deliveryRegion.add("法国");
//			createFreightDetailDto1.setDeliveryRegion(deliveryRegion);
			createFreightDetailDto1.setDeliveryRegion(Arrays.asList("湖北省","法国"));
			createFreightDetailDto1.setFirstNum(1);
			createFreightDetailDto1.setFirstFee(new BigDecimal(0));
			createFreightDetailDto1.setAddFee(new BigDecimal(0));
			createFreightDetailDto1.setAddNum(5);
			List<CreateFreightDetailDto> templateItems = new ArrayList<>();
			templateItems.add(createFreightDetailDto1);
			templateItems.add(createfreighttemplateBean.getMainFreight().getTemplateItems().get(0));
			createfreighttemplateBean.getMainFreight().setCalcModel(1);
			createfreighttemplateBean.getMainFreight().setTemplateItems(templateItems);

			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("200",createfreighttemplateCall.getString("code"),"验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_36() {
		Logger.start(true,"渠道商创建主运费模板和代理运费模板，渠道支持海外地址,地区都是海外地址创建成功");
		try {
			Integer mchId=500802465;

			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(mchId,1,2);

			CreateFreightDto createFreightDto = new CreateFreightDto();
			int calcModel = 1;
			createFreightDto.setCalcModel(calcModel);
			CreateFreightDetailDto createFreightDetailDto1 = setCreateFreightDetailDto(calcModel);
			
			createFreightDetailDto1.setDeliveryRegion(Arrays.asList("湖北省","上海市"));
			createFreightDetailDto1.setFirstNum(1);
			createFreightDetailDto1.setFirstFee(new BigDecimal(0));
			createFreightDetailDto1.setAddFee(new BigDecimal(0));
			createFreightDetailDto1.setAddNum(5);
			List<CreateFreightDetailDto> templateItems = new ArrayList<>();
			templateItems.add(createFreightDetailDto1);
			templateItems.add(createfreighttemplateBean.getMainFreight().getTemplateItems().get(0));
			createfreighttemplateBean.getMainFreight().setCalcModel(1);
			createfreighttemplateBean.getMainFreight().setTemplateItems(templateItems);

			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("200",createfreighttemplateCall.getString("code"),"验证code");
			int templateId = createfreighttemplateCall.getJsonObject().get("data").getAsJsonObject().get("templateId").getAsInt();
			verifyDB(createfreighttemplateBean,templateId);
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_37() {
		Logger.start(true,"渠道商创建主运费模板和代理运费模板，渠道支持海外地址,地区包括海外和国内地址创建成功");
		try {
			Integer mchId=500802465;

			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(mchId,1,2);

			CreateFreightDto createFreightDto = new CreateFreightDto();
			int calcModel = 1;
			createFreightDto.setCalcModel(calcModel);
			CreateFreightDetailDto createFreightDetailDto1 = setCreateFreightDetailDto(calcModel);
			createFreightDetailDto1.setDeliveryRegion(Arrays.asList("上海市","法国"));
			createFreightDetailDto1.setFirstNum(1);
			createFreightDetailDto1.setFirstFee(new BigDecimal(0));
			createFreightDetailDto1.setAddFee(new BigDecimal(0));
			createFreightDetailDto1.setAddNum(5);
			List<CreateFreightDetailDto> templateItems = new ArrayList<>();
			templateItems.add(createFreightDetailDto1);
			templateItems.add(createfreighttemplateBean.getMainFreight().getTemplateItems().get(0));
			createfreighttemplateBean.getMainFreight().setCalcModel(1);
			createfreighttemplateBean.getMainFreight().setTemplateItems(templateItems);

			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("200",createfreighttemplateCall.getString("code"),"验证code");
			
			int templateId = createfreighttemplateCall.getJsonObject().get("data").getAsJsonObject().get("templateId").getAsInt();
			verifyDB(createfreighttemplateBean,templateId);
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_38() {
		Logger.start(true,"渠道商创建主运费模板和代理运费模板，渠道支持海外地址,地区包括不存在的地址,创建失败");
		try {
			
			Integer mchId=500802465;

			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(mchId,1,2);

			CreateFreightDto createFreightDto = new CreateFreightDto();
			int calcModel = 1;
			createFreightDto.setCalcModel(calcModel);
			CreateFreightDetailDto createFreightDetailDto1 = setCreateFreightDetailDto(calcModel);
			createFreightDetailDto1.setDeliveryRegion(Arrays.asList("上海市","法国","不存在地址"));
			createFreightDetailDto1.setFirstNum(1);
			createFreightDetailDto1.setFirstFee(new BigDecimal(0));
			createFreightDetailDto1.setAddFee(new BigDecimal(0));
			createFreightDetailDto1.setAddNum(5);
			List<CreateFreightDetailDto> templateItems = new ArrayList<>();
			templateItems.add(createFreightDetailDto1);
			templateItems.add(createfreighttemplateBean.getMainFreight().getTemplateItems().get(0));
			createfreighttemplateBean.getMainFreight().setCalcModel(1);
			createfreighttemplateBean.getMainFreight().setTemplateItems(templateItems);

			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("400",createfreighttemplateCall.getString("code"),"验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CreateFreightTemplate_39() {
		Logger.start(true,"渠道商创建主运费模板和代理运费模板，渠道不支持海外地址,地区国外地区,创建失败");
		try {
			createmchBean createmchBean = GodmchManageCallService.InitcreatemchBeanForChannel();
			GodmchManageCallService.createmchCallForChannel(createmchBean);

			createfreighttemplateBean = GodfreightmgrService.initCreateFreightTemplate(createmchBean.getMchId(),1,2);

			CreateFreightDto createFreightDto = new CreateFreightDto();
			int calcModel = 1;
			createFreightDto.setCalcModel(calcModel);
			CreateFreightDetailDto createFreightDetailDto1 = setCreateFreightDetailDto(calcModel);
			createFreightDetailDto1.setDeliveryRegion(Arrays.asList("湖北省","上海市","法国"));
			createFreightDetailDto1.setFirstNum(1);
			createFreightDetailDto1.setFirstFee(new BigDecimal(0));
			createFreightDetailDto1.setAddFee(new BigDecimal(0));
			createFreightDetailDto1.setAddNum(5);
			List<CreateFreightDetailDto> templateItems = new ArrayList<>();
			templateItems.add(createFreightDetailDto1);
			templateItems.add(createfreighttemplateBean.getMainFreight().getTemplateItems().get(0));
			createfreighttemplateBean.getMainFreight().setCalcModel(1);
			createfreighttemplateBean.getMainFreight().setTemplateItems(templateItems);

			createfreighttemplateCall.setData(createfreighttemplateBean);
			createfreighttemplateCall.callService();
			Logger.verifyEquals("400",createfreighttemplateCall.getString("code"),"验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}